package czk.concrent.lockSupport;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/5/30 21:43
 */
// lockSupport demo
public class Test {
    public static void main(String[] args) throws InterruptedException {
        Thread t1=new Thread(()->{
            System.out.println(Thread.currentThread().getName()+"开始运行了");
            // 停止两秒
            try {
                Thread.sleep(2*1000);
                System.out.println(Thread.currentThread().getName()+"我要进入waitSet了");
                // 此时不会阻塞，locksupport是基于计数的，下面已经将树加一，此时减11刚好持平
                LockSupport.park();
                System.out.println(Thread.currentThread().getName()+"被唤醒了");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        },"t1");
        t1.start();
        // 主线程
        TimeUnit.SECONDS.sleep(1);
        LockSupport.unpark(t1);
    }
}
